Imports Microsoft.VisualBasic
Imports sk.DAL

Public Class ArticleObj
    Inherits BizObject


    Sub New(ByVal ID As Integer, ByVal user As String, ByVal title As String, ByVal text As String, ByVal Creation As Date, ByVal expiration As Date, ByVal post As Date, ByVal approve As Boolean, ByVal category As Integer)
        _ArticleID = ID
        _UserID = user
        _Title = title
        _Text = text
        _CreationDate = Creation
        _ExpirationDate = expiration
        _PostDate = post
        _Approved = approve
        _CategoryID = category
    End Sub

    Sub New()

    End Sub

    Private _ArticleID As Integer
    Public Property ArticleID() As Integer
        Get
            Return _ArticleID
        End Get
        Set(ByVal value As Integer)
            _ArticleID = value
        End Set
    End Property


    Private _UserID As String
    Public Property UserID() As String
        Get
            Return _UserID
        End Get
        Set(ByVal value As String)
            _UserID = value
        End Set
    End Property


    Private _Title As String
    Public Property Title() As String
        Get
            Return _Title
        End Get
        Set(ByVal value As String)
            _Title = value
        End Set
    End Property


    Private _Text As String
    Public Property Text() As String
        Get
            Return _Text
        End Get
        Set(ByVal value As String)
            _Text = value
        End Set
    End Property


    Private _CreationDate As Date
    Public Property CreationDate() As Date
        Get
            Return _CreationDate
        End Get
        Set(ByVal value As Date)
            _CreationDate = value
        End Set
    End Property


    Private _ExpirationDate As Date
    Public Property ExpirationDate() As Date
        Get
            Return _ExpirationDate
        End Get
        Set(ByVal value As Date)
            _ExpirationDate = value
        End Set
    End Property


    Private _PostDate As Date
    Public Property PostDate() As Date
        Get
            Return _PostDate
        End Get
        Set(ByVal value As Date)
            _PostDate = value
        End Set
    End Property


    Private _Approved As Boolean
    Public Property Approved() As Boolean
        Get
            Return _Approved
        End Get
        Set(ByVal value As Boolean)
            _Approved = value
        End Set
    End Property


    Private _CategoryID As Integer
    Public Property CategoryID() As Integer
        Get
            Return _CategoryID
        End Get
        Set(ByVal value As Integer)
            _CategoryID = value
        End Set
    End Property

    Public Function ChangeArticleApproval(ByVal ArticleID As Integer, ByVal status As Boolean) As Boolean
        Try
            Dim provider As ArticleProvider
            provider = ArticleProvider.Instance
            provider.ChangeArticleApproval(ArticleID, status)
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function CreateArticle(ByVal obj As ArticleObj) As Boolean
        Try
            Dim article As New Article
            Dim provider As ArticleProvider

            provider = ArticleProvider.Instance
            article.Approved = True
            article.CategoryID = obj.CategoryID
            article.CreationDate = Date.Today
            article.ExpirationDate = obj.ExpirationDate
            article.PostDate = obj.PostDate
            article.Text = obj.Text
            article.Title = obj.Title
            article.UserID = obj.UserID

            provider.CreateArticle(article)
            Return True

        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function DeleteArticle(ByVal Article As Article) As Boolean
        Try
            Dim provider As ArticleProvider
            provider = ArticleProvider.Instance
            provider.DeleteArticle(Article.ArticleID)
            Return True

        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function GetAllArticles() As System.Collections.Generic.List(Of Article)
        Try
            Dim provider As ArticleProvider
            provider = ArticleProvider.Instance
            Return provider.GetAllArticles()

        Catch ex As Exception
            Return New System.Collections.Generic.List(Of Article)
        End Try
    End Function

    Public Function GetArticleByID(ByVal AtcleID As Integer) As ArticleObj
        Try

            Dim provider As ArticleProvider
            provider = ArticleProvider.Instance
            Dim obj As New ArticleObj
            Dim article As Article = provider.GetArticleByID(AtcleID)

            obj.ArticleID = article.ArticleID
            obj.Approved = article.Approved
            obj.CategoryID = article.CategoryID
            obj.CreationDate = article.CreationDate
            obj.ExpirationDate = article.ExpirationDate
            obj.PostDate = article.PostDate
            obj.Text = article.Text
            obj.Title = article.Title
            obj.UserID = article.UserID

            Return obj


        Catch ex As Exception
            Return New ArticleObj
        End Try
    End Function

    Public Function UpdateArticle(ByVal obj As ArticleObj) As Boolean
        Try

            Dim provider As ArticleProvider
            provider = ArticleProvider.Instance
            Dim Article As New Article
            Article.ArticleID = obj.ArticleID
            Article.Approved = obj.Approved
            Article.CategoryID = obj.CategoryID
            Article.CreationDate = obj.CreationDate
            Article.ExpirationDate = obj.ExpirationDate
            Article.PostDate = obj.PostDate
            Article.Text = obj.Text
            Article.Title = obj.Title
            Article.UserID = obj.UserID
            provider.UpdateArticle(Article)
            Return True

        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function UpdateArticleText(ByVal ArticleId As Integer, ByVal updatedText As String) As Boolean
        Try
            Dim provider As ArticleProvider
            provider = ArticleProvider.Instance
            provider.UpdateArticleText(ArticleId, updatedText)
            Return True

        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function UpdateExpireDate(ByVal ArticleID As Integer, ByVal newExpireDate As Date) As Boolean
        Try

            Dim provider As ArticleProvider
            provider = ArticleProvider.Instance
            provider.UpdateExpireDate(ArticleID, newExpireDate)
            Return True

        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function UpdatePostDate(ByVal ArticleID As Integer, ByVal newPostDate As Date) As Boolean
        Try
            Dim provider As ArticleProvider
            provider = ArticleProvider.Instance
            provider.UpdatePostDate(ArticleID, newPostDate)
            Return True

        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function GetArticlesByUserID(ByVal UserID As String) As System.Collections.Generic.List(Of Article)
        Try
            Dim provider As ArticleProvider
            provider = ArticleProvider.Instance
            Return provider.GetArticlesByUserID(UserID)
        Catch ex As Exception
            Return New System.Collections.Generic.List(Of Article)
        End Try
    End Function

    Public Function GetArticlesOnCreationDate(ByVal ArticleDate As Date) As System.Collections.Generic.List(Of Article)
        Try
            Dim provider As ArticleProvider
            provider = ArticleProvider.Instance
            Return provider.GetArticlesOnCreationDate(ArticleDate)
        Catch ex As Exception
            Return New System.Collections.Generic.List(Of Article)
        End Try
    End Function

    Public Function GetArticlesOnExpireDate(ByVal ArticleDate As Date) As System.Collections.Generic.List(Of Article)
        Try
            Dim provider As ArticleProvider
            provider = ArticleProvider.Instance
            Return provider.GetArticlesOnExpireDate(ArticleDate)
        Catch ex As Exception
            Return New System.Collections.Generic.List(Of Article)
        End Try
    End Function

    Public Function GetArticlesOnPostDate(ByVal ArticleDate As Date) As System.Collections.Generic.List(Of Article)
        Try
            Dim provider As ArticleProvider
            provider = ArticleProvider.Instance
            Return provider.GetArticlesOnPostDate(ArticleDate)
        Catch ex As Exception
            Return New System.Collections.Generic.List(Of Article)
        End Try
    End Function

    Public Function GetCurrentArticles() As System.Collections.Generic.List(Of ArticleObj)
        Try
            Dim provider As ArticleProvider
            Dim a As Article
            provider = ArticleProvider.Instance
            Dim objList As New Generic.List(Of ArticleObj)
            Dim artList As Generic.List(Of Article)
            artList = provider.GetCurrentArticles()
            For Each a In artList
                objList.Add(New ArticleObj(a.ArticleID, a.UserID, a.Title, a.Text, a.CreationDate, a.ExpirationDate, a.PostDate, a.Approved, a.CategoryID))
            Next
            Return objList
        Catch ex As Exception
            Return New System.Collections.Generic.List(Of ArticleObj)
        End Try
    End Function

    Public Function GetNextID() As Integer
        Dim provider As ArticleProvider
        provider = ArticleProvider.Instance
        Return provider.GetNextID
    End Function


End Class
